﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.PeerResolvers;
using System.ServiceModel;

namespace NameResolver
{
    public static class PeerResolver
    {
        static CustomPeerResolverService crs;
        static ServiceHost customResolver;

        public static void Start() 
        {
            if (crs == null && customResolver == null)
            {
                crs = new CustomPeerResolverService();
                crs.ControlShape = false;
                customResolver = new ServiceHost(crs);
                crs.Open();
                customResolver.BeginOpen((AsyncCallback)((t) => 
                {
                    //App.Log.Info("Служба разрешения имен запущена успешно!");
                    App.ViewModel.AddLogMessage("Служба разрешения имен запущена успешно!");
                }), null);//.Open();
            }
        }

        public static void Stop()
        {
            crs.Close();
            customResolver.Close();
            crs = null;
            customResolver = null;
        }
    }
}
